// 对axios做二次封装
import axios from "axios"

const request=axios.create({
    baseURL:'',
    timeout:5000
})
request.interceptors.request.use(function(config){
      return {
          ...config,
          headers:{
              ...config.headers,
          }
      }
},function(error){
    return Promise.reject(error)
})
request.interceptors.response.use(function(response){
      return response
},function(error){
    switch (error.response.status) {
        case 404:
            alert('接口没有找到')
            break;
        case 403:
            alert('没有权限')
            break;
        case 500:
             alert('服务器内部错误')
            break;
        case 406:
            alert('参数不合法')
            break;
        default:
            break;
    }
    return Promise.reject(error)
})

export default{
     get(url,params){
         return request.get(url,{params})
     },
     post(url,params){
         return request.post(url,params)
     },
     delete(url,params){
         return request.delete(url,{params})
     },
     put(url,params){
         return request.put(url,params)
     }
}
